<template>
    <div class="mui-numbox" data-numbox-min='1'>
        <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
        <input id="test" class="mui-input-numbox" type="number" value="1" @change="countChanged" ref="numbox"/>
        <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
    </div>
</template>

<script>
//导入mui
import mui from '../../lib/mui/js/mui.min.js'
export default {
    data() {
        return {

        }
    },
    methods: {
        countChanged() {    
            //每当文本框的值改变时 立即把数据 通过事件调用的方式传递给父组件
            this.$emit('getCount',parseInt(this.$refs.numbox.value))
        }
    },
    props: [
        'maxNum'
    ],
    watch:  {
        maxNum: function(newVal,oldVal) {
            //使用numbox的js api设置最大值
            mui('.mui-numbox').numbox().setOption('max',newVal)
        }
    },
    mounted() {
        //初始化数字选择框
        mui('.mui-numbox').numbox()
    }
}
</script>

<style lang="scss" scoped>

</style>